package shark.flow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shark.common.model.Result;
import shark.flow.service.IFlowTaskService;
import shark.flow.vo.CompleteTaskVo;
import shark.flow.vo.TaskQueryParamsVo;
import shark.flow.vo.TaskVo;

@RestController
@RequestMapping("/task")
public class FlowTaskController {

    @Autowired
    private IFlowTaskService taskService;

    @PostMapping("/complete")
    public Result<Boolean> completeTask(@RequestBody CompleteTaskVo completeTaskVo) {
        Boolean result = taskService.complete(completeTaskVo);
        if (result == false) {
            return new Result<>(500, "failed", false);
        }
        return new Result<>(200, "success", true);
    }

    @PostMapping("/todo")
    public Result<IPage<TaskVo>> getTodoTask(@RequestBody TaskQueryParamsVo queryParamsVo) {
        IPage<TaskVo> page = taskService.getTodoTasks(queryParamsVo);
        Result<IPage<TaskVo>> result = new Result<>(200, "success!", page);
        return result;
    }
}
